/*
dryer_door.h
offer dryer door control api and data type define
designed by lunanting

----------------------
2020-11-10 11:18:45
create file
----------------------
*/
#ifndef __DRYER_DOOR_H
#define __DRYER_DOOR_H

#include "../../bsp/base_type.h"
#include "../../../include/aos/kernel.h"

/**********************config************************/
#define DRYER_DOOR_ratio    6.15    //减速比
#define DRYER_DOOR_dis      5       //螺距 mm
#define DRYER_DOOR_speed    300     //电机转速 r/min


//io
#define DRYER_DOOR_limit_left_open    17  //左门开限位
#define DRYER_DOOR_limit_left_close   16  //左门关限位
#define DRYER_DOOR_limit_right_open   13  //右门开限位
#define DRYER_DOOR_limit_right_close  12  //右门关限位

#define DRYER_DOOR_io_touched   0   //io触发状态


/********************************data type define******************************/
//door data
typedef struct{
    u8 port;    //can port
    u8 node;  //door slave id
    u8 state;   //door state,0=close,1=open
    s8 dir; //door move direction
    u8 error;   //error state
    u8 mark;    //标志，0=left door,1=right door
    aos_mutex_t mux;
    aos_sem_t sem;  
    int location;   //door location
    int target;     //target position
    int pluse_speed;    //pluse speed pluse/s
}DRYER_DOOR_door;

//door property
typedef struct{
    u8 init;    //dryer door init status
    int speed;    //speed r/min
    u8 state;   //door state,0=close,1=open
    int targe_location;  //target lication
    aos_mutex_t mux;    //dryer door move mux
    DRYER_DOOR_door left_door;   //dryer left door
    DRYER_DOOR_door right_door;   //dryer right door
}DRYER_DOOR;




/***************************function extern***************************/
extern int xp_dryerDoor_init(u8 nodeL,u8 nodeR,u16 speed);  //dyer door init
extern int xp_dryerDoor_move(DRYER_DOOR_door *dr,int dis);  //door move
extern int xp_dryerDoor_move_set(DRYER_DOOR_door *dr,int dis);  //move door set
extern void xp_dryerDoor_move_clear(DRYER_DOOR_door *dr);   //clear door move
extern int xp_dryerDoor_all_set(int dis);   //dryer door all set
extern void xp_dryerDoor_all_clear(void);   //dryer door all move clear
extern int xp_dryerDoor_set(u8 sta);    //dryer door set

extern int xp_dryerDoor_debug(char *type,char *fun,char *param);



#endif
//end of the file
